import pandas as pd
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome(service=Service('D:\\myproject\\feng-huang\\1.自动化\\1.selenium\\chromedriver.exe'))
driver.maximize_window()
driver.get('https://www.foodtalks.cn/company/Yili/')
time.sleep(2)
dict = {}
driver.find_element(By.CLASS_NAME, 'tab-item').click()
time.sleep(2)
# 中文全称
company_name = driver.find_element(By.XPATH, '//div[text()="中文全称："]')
if company_name.text == '中文全称：':
    try:
        company_name1 = company_name.find_element(By.XPATH, "./following-sibling::*[1]").text
    except:
        company_name1 = ''
    dict['公司名称'] = company_name1
# 中文简称
company_name_short = driver.find_element(By.XPATH, '//div[text()="中文简称："]')
if company_name_short.text == '中文简称：':
    try:
        company_name_short1 = company_name_short.find_element(By.XPATH, "./following-sibling::*[1]").text
    except:
        company_name_short1 = ''
    dict['公司简称'] = company_name_short1
# 英文全称
company_name_en = driver.find_element(By.XPATH, '//div[text()="英文全称："]')
if company_name_en.text == '英文全称：':
    try:
        company_name_en1 = company_name_en.find_element(By.XPATH, "./following-sibling::*[1]").text
    except:
        company_name_en1 = ''
    dict['英文名称'] = company_name_en1
# 英文简称
company_name_short_en = driver.find_element(By.XPATH, '//div[text()="英文简称："]')
if company_name_short_en.text == '英文简称：':
    try:
        company_name_short_en1 = company_name_short_en.find_element(By.XPATH, "./following-sibling::*[1]").text
    except:
        company_name_short_en1 = ''
    dict['英文简称'] = company_name_short_en1
# 公司类型
company_type = driver.find_element(By.XPATH, '//div[text()="公司类型："]')
if company_type.text == '公司类型：':
    try:
        company_type1 = company_type.find_element(By.XPATH, "./following-sibling::*[1]").text
    except:
        company_type1 = ''
    dict['公司类型'] = company_type1
# 成立时间
establish_time = driver.find_element(By.XPATH, '//div[text()="成立时间："]')
if establish_time.text == '成立时间：':
    try:
        establish_time1 = establish_time.find_element(By.XPATH, "./following-sibling::*[1]").text
    except:
        establish_time1 = ''
    dict['成立时间'] = establish_time1
# 股票代码
stock_code = driver.find_element(By.XPATH, '//div[text()="股票代码："]')
if stock_code.text == '股票代码：':
    try:
        stock_code1 = stock_code.find_element(By.XPATH, "./following-sibling::*[1]").text
    except:
        stock_code1 = ''
    dict['股票代码'] = stock_code1
# 公司总机
company_tel = driver.find_element(By.XPATH, '//div[text()="公司总机："]')
if company_tel.text == '公司总机：':
    try:
        company_tel1 = company_tel.find_element(By.XPATH, "./following-sibling::*[1]").text
    except:
        company_tel1 = ''
    dict['公司总机'] = company_tel1
# 公司性质
company_property = driver.find_element(By.XPATH, '//div[text()="公司性质："]')
if company_property.text == '公司性质：':
    try:
        company_property1 = company_property.find_element(By.XPATH, "./following-sibling::*[1]").text
    except:
        company_property1 = ''
    dict['公司性质'] = company_property1
# 行业分类
industry_classification = driver.find_element(By.XPATH, '//div[text()="行业分类："]')
if industry_classification.text == '行业分类：':
    try:
        industry_classification1 = industry_classification.find_element(By.XPATH, "./following-sibling::*[1]").text
    except:
        industry_classification1 = ''
    dict['行业分类'] = industry_classification1
# 主要品牌
main_brand = driver.find_element(By.XPATH, '//div[text()="主要品牌："]')
if main_brand.text == '主要品牌：':
    try:
        main_brand1 = main_brand.find_element(By.XPATH, "./following-sibling::*[1]").text
    except:
        main_brand1 = ''
    dict['主要品牌'] = main_brand1
# 主要产品
main_product = driver.find_element(By.XPATH, '//div[text()="主要产品："]')
if main_product.text == '主要产品：':
    try:
        main_product1 = main_product.find_element(By.XPATH, "./following-sibling::*[1]").text
    except:
        main_product1 = ''
    dict['主要产品'] = main_product1
# 公司官网
company_website = driver.find_element(By.XPATH, '//div[text()="公司官网："]')
if company_website.text == '公司官网：':
    try:
        company_website1 = company_website.find_element(By.XPATH, "./following-sibling::*[1]").text
    except:
        company_website1 = ''
    dict['公司官网'] = company_website1
# 公司总部
company_headquarters = driver.find_element(By.XPATH, '//div[text()="公司总部："]')
if company_headquarters.text == '公司总部：':
    try:
        company_headquarters1 = company_headquarters.find_element(By.XPATH, "./following-sibling::*[1]").text
    except:
        company_headquarters1 = ''
    dict['公司总部'] = company_headquarters1
# 总部地址
headquarters_address = driver.find_element(By.XPATH, '//div[text()="总部地址："]')
if headquarters_address.text == '总部地址：':
    try:
        headquarters_address1 = headquarters_address.find_element(By.XPATH, "./following-sibling::*[1]").text
    except:
        headquarters_address1 = ''
    dict['总部地址'] = headquarters_address1
# 简介
unfold_more = driver.find_element(By.XPATH, '//span[text()="展开"]').click()
introduction = driver.find_element(By.XPATH, '//span[text()="公司介绍"]')
if introduction.text == '公司介绍':
    try:
        introduction1 = introduction.find_element(By.XPATH , '//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[1]/div[1]/div[2]/div[1]').text
    except:
        introduction1 = ''
    dict['公司介绍'] = introduction1
# 品牌
brand = driver.find_element(By.XPATH, '//span[text()="品牌"]')
if brand.text == '品牌':
    brand.click()
    list_brand = []
    try:
        brands1 = driver.find_elements(By.CLASS_NAME,'el-row')
        for brand11 in brands1:
            brand111 = brand11.find_element(By.CLASS_NAME, 'name.ellipsis2').text
            list_brand.append(brand111)
    except:
        brand1 = ''
    dict['品牌'] = list_brand
print(dict)
